/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.shop;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.hk.shop.entity.shop.HkUserShop;
import com.thinkgem.jeesite.modules.hk.shop.service.shop.HkUserShopService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 店铺管理Controller
 * @author 李欣荣
 * @version 2018-10-08
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/shop/hkUserShop")
public class HkUserShopController extends BaseController {

	@Autowired
	private HkUserShopService hkUserShopService;
	
	@ModelAttribute
	public HkUserShop get(@RequestParam(required=false) String id) {
		HkUserShop entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkUserShopService.get(id);
		}
		if (entity == null){
			entity = new HkUserShop();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:shop:hkUserShop:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkUserShop hkUserShop, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkUserShop> page = hkUserShopService.findPage(new Page<HkUserShop>(request, response), hkUserShop); 
		model.addAttribute("page", page);
		return "hk/shop/shop/hkUserShopList";
	}

	@RequiresPermissions("shop:shop:hkUserShop:view")
	@RequestMapping(value = "form")
	public String form(HkUserShop hkUserShop, Model model) {
		model.addAttribute("hkUserShop", hkUserShop);
		return "hk/shop/shop/hkUserShopForm";
	}

	@RequiresPermissions("shop:shop:hkUserShop:edit")
	@RequestMapping(value = "save")
	public String save(HkUserShop hkUserShop, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkUserShop)){
			return form(hkUserShop, model);
		}
		hkUserShopService.save(hkUserShop);
		addMessage(redirectAttributes, "保存店铺管理成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkUserShop/?repage";
	}
	
	@RequiresPermissions("shop:shop:hkUserShop:edit")
	@RequestMapping(value = "delete")
	public String delete(HkUserShop hkUserShop, RedirectAttributes redirectAttributes) {
		hkUserShopService.delete(hkUserShop);
		addMessage(redirectAttributes, "删除店铺管理成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkUserShop/?repage";
	}

}